Skip to content

feat(collector/receiver): support extra fields in structured JSON function logs#2251

Open
tomsobpl wants to merge 11 commits intoopen-telemetry:mainfrom
tomsobpl:feat/extra-fields-support-in-json-logging
Open

feat(collector/receiver): support extra fields in structured JSON function logs#2251
tomsobpl wants to merge 11 commits intoopen-telemetry:mainfrom
tomsobpl:feat/extra-fields-support-in-json-logging

Conversation

@tomsobpl
Copy link
Copy Markdown

Summary

When a Lambda function emits structured JSON logs (i.e., a log line with a message field), the telemetryapireceiver now extracts any additional fields from the JSON object and maps them to log record attributes.

Previously, only the message field was captured from structured JSON log records. Any extra fields present in the JSON object (e.g., userId, orderId, custom business data) were silently discarded.

{ "message": "order processed", "orderId": "123", "userId": "abc", "level": "info" }

Before:
→ Log record body: "order processed", no extra attributes.

After:
→ Log record body: "order processed", attributes: orderId = "123", userId = "abc".

Changes

  • receiver.go: After setting the log record body from the message field, iterate over all remaining keys in the parsed JSON record and add them as log record attributes. The well-known fields (level, message, requestId, timestamp) are skipped since they are already handled separately.
  • receiver_test.go: Extended test coverage for JSON logs containing extra fields, covering nested values, arrays, and numeric types.

Notes:

  • The attribute key names are taken as-is from the JSON log (no prefix added), keeping the mapping straightforward.
  • Values that cannot be converted via pcommon.Value.FromRaw emit a warning and are skipped rather than failing the entire record.

@tomsobpl tomsobpl requested a review from a team as a code owner April 14, 2026 06:24
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 14, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@wpessers wpessers added bug Something isn't working go Pull requests that update Go code labels Apr 14, 2026
Comment thread collector/receiver/telemetryapireceiver/receiver.go
Comment thread collector/receiver/telemetryapireceiver/receiver.go Outdated
Comment thread collector/receiver/telemetryapireceiver/receiver.go Outdated
Comment thread collector/receiver/telemetryapireceiver/receiver_test.go Outdated
@tomsobpl
Copy link
Copy Markdown
Author

Hey @wpessers, I've updated the code and addressed all the feedback.

@RaphaelManke
Copy link
Copy Markdown
Contributor

Is this one solving #2173
Or at least partially?

@tomsobpl
Copy link
Copy Markdown
Author

Is this one solving #2173 Or at least partially?

@RaphaelManke partially yes. It introduces support for extra logs metadata but without any transformation. Everything is in developers hands as this just copy 1:1 json logs metadata fields into otel attributes

@wpessers
Copy link
Copy Markdown
Member

LGTM, waiting to merge to allow @RaphaelManke to give feedback if he wants since the PR is relevant to that issue he still has open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants